package cn.tedu.cwfw.pet.service.impl;

import cn.tedu.cwfw.pet.mapper.PetMapper;
import cn.tedu.cwfw.pet.pojo.dto.PetSaveParam;
import cn.tedu.cwfw.pet.pojo.entity.Pet;
import cn.tedu.cwfw.pet.pojo.vo.PetVO;
import cn.tedu.cwfw.pet.service.PetService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class PetServiceImpl implements PetService {

    @Autowired
    PetMapper petMapper;
    @Override
    public void insert(PetSaveParam petSaveParam) {
        log.debug("添加宠物信息:{}", petSaveParam);
        petMapper.insert(petSaveParam);
        log.debug("添加宠物信息成功");

    }

    @Override
    public void delete(Long id) {
        log.debug("删除宠物信息:{}", id);
        petMapper.delete(id);
        log.debug("删除宠物信息成功");
    }

    @Override
    public void update(PetSaveParam petSaveParam) {
        log.debug("修改宠物信息:{}", petSaveParam);
        Pet pet = new Pet();
        BeanUtils.copyProperties(petSaveParam, pet);
        pet.setUpdateTime(new Date());

        petMapper.update(pet);
        log.debug("修改宠物信息成功");
    }

    @Override
    public List<PetVO> findPet(Long clientId) {
        log.debug("查询宠物信息:{}", clientId);
        List<PetVO> petVOS = petMapper.findPet(clientId);
        return petVOS;
    }

    @Override
    public PetVO findById(Long id) {
        log.debug("根据id查询宠物信息:{}", id);
        PetVO petVO = petMapper.findById(id);
        return petVO;
    }
}
